﻿using UnityEngine;
using System.Collections;

public class xiao_BOSS1 : MonoBehaviour {

	//移动速度
	public float enemy_Speed = 1;
	//敌人的生命
	int enemy_Life = 50;
	//是否移动
	protected bool yidong_Bool = true;
	Transform m_Transform;
	void Start () {
		
		m_Transform = this.transform;
	}
	void Update () {
		
		UpdateMove();
	}
	
	protected void UpdateMove()
	{
		if (yidong_Bool)
		{
			m_Transform.Translate(0, enemy_Speed * Time.deltaTime, 0);
		}
	}
	
	void OnTriggerEnter2D(Collider2D other)
	{
		if (other.tag.CompareTo("PlayerRocket1") == 0)
		{
			Rocket1 rocket = other.GetComponent<Rocket1>();
			if (rocket != null)
			{
				enemy_Life -= rocket.rocket_Power;
				Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[11].ToString()),rocket.transform.position,Quaternion.identity);
				Destroy(rocket.gameObject);
				if (enemy_Life <= 0)
				{
					this.teXiao();
					
				}
			}
		}
		if(other.tag.CompareTo("PlayerRocket2") == 0)
		{
			Rocket2 rocket2 = other.GetComponent<Rocket2>();
			if (rocket2 != null)
			{
				enemy_Life -= rocket2.rocket_Power;
				Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[11].ToString()),rocket2.transform.position,Quaternion.identity);
				Destroy(rocket2.gameObject);
				if (enemy_Life <= 0)
				{
					this.teXiao();
					
				}
			}
		}
        if(other.tag.CompareTo("PlayerRocket3") == 0)
		{
			Rocket3 rocket3 = other.GetComponent<Rocket3>();
			if(rocket3!=null)
			{
				enemy_Life -= rocket3.rocket_power;
                Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[11].ToString()), rocket3.transform.position, Quaternion.identity);
				Destroy(rocket3.gameObject);
				if (enemy_Life <= 0)
				{
					this.teXiao();
					
				}
			}
	    }
        if(other.tag.CompareTo("HeDan") ==0 )
		{
			this.teXiao();
		}
        if(other.tag.CompareTo("Bounds") == 0)
		{
			Destroy(this.gameObject);
		}
	}
	
	//爆炸并且播放音效
	protected void teXiao()
	{
		yidong_Bool = false;
		Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[11].ToString()), m_Transform.position, Quaternion.identity);
		Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[19].ToString()),m_Transform.position,Quaternion.identity);
		//出现钻石
		int number =0;
		number = Random.Range(9,12);
		GameObject obj_ZuanShi = Resources.Load<GameObject>(SampleXml.prefabPath[5].ToString());
		for(int i=0;i<number;i++)
		{
			Instantiate(obj_ZuanShi,this.ZuanShiPosition(m_Transform.position),Quaternion.identity);
		}
		this.random_Daoju();
		Destroy(this.gameObject);     
	}
	//金币移动出现
	protected Vector3 ZuanShiPosition(Vector3 vec)
	{
		Vector3 vec3 = new Vector3(Random.Range(vec.x-1,vec.x+1),Random.Range(vec.y-1,vec.y+1),0);
		return vec3;
	}
    //随机出现道具
	protected void random_Daoju()
	{
		int state = Random.Range(0,6);
		switch(state)
		{
		case 0:
			Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[13].ToString()),m_Transform.position,Quaternion.identity);
			break;
		case 1:
			Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[21].ToString()),m_Transform.position,Quaternion.identity);
			break;
		case 2:
			Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[22].ToString()),m_Transform.position,Quaternion.identity);
			break;
		}
	}
}
